package com.begood.leishi.fingerprinter.utils;

import android.content.Context;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 调试信息日志
 * Created by leishi on 2017/11/30.
 */

public class Slog {
    Context mContext;
    FileOutputStream mOut;
    boolean errorFlag = false;
    public Slog(Context context){
        mContext = context;
        File file = new File(mContext.getExternalFilesDir("")+"/log.txt");
        try {
            if (!file.exists ()) {
                file.createNewFile();
            }
            mOut = new FileOutputStream(file);
        }catch (Exception e){
            errorFlag = true;
        }
    }
    public void log(String text){
        if(errorFlag){
            return;
        }
        String time = (new SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.getDefault())).format(new Date());
        String temp = time+"\t"+text+"\n";
        try {
            mOut.write(temp.getBytes());
        }catch (Exception e){

        }
    }
    public void free(){
        try {
            mOut.close();
        }catch (Exception e){
        }

    }
}
